package com.lagou.mq.service;

import com.lagou.mq.mapper.OrderMapper;
import com.lagou.mq.pojo.Order;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @Description TODO
 * @Classname MyConsumer
 * @Date 2021/7/21 20:29
 * @Author ch'ien
 */
@Component
public class MyConsumer {

    @Autowired
    private OrderMapper orderMapper;

    @RabbitListener(queues = "q.dlx")
    public void myLister(@Payload String id){
        System.out.println("订单到期");
        Order one = orderMapper.getOneByOrderNo(id);
        if (one != null && one.getId() !=null
            && Objects.equals(0, one.getStatus())){
            // 2未支付失效订单
            one.setStatus(2);
            orderMapper.update(one);
        }


    }
}
